<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-canteens__batchorder}">
      <el-form :inline="true" :model="topData" @keyup.enter.native="getTableData()">
        <el-form-item>
          <el-select v-model="topData.canteenId" placeholder="请选择">
            <el-option label="全部" value></el-option>
            <el-option label="新食堂" value="1198803185855877122"></el-option>
            <el-option label="老食堂" value="1067246875800000066"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="topData.s" placeholder="请选择">
            <el-option label="全部" value="2"></el-option>
            <el-option label="待提交" value="item.value"></el-option>
            <el-option label="已提交" value="item.value"></el-option>
            <el-option label="已完成" value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="topData.batchOrderId" placeholder="请输入清单名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getTableData()">查询</el-button>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="addData()">新增</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="upDateOrder()">提交</el-button>
        </el-form-item>

      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="selectChange"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="batchOrderName" label="清单名称" header-align="center" align="center"></el-table-column>
        <el-table-column label="发起人" header-align="center" align="center">
          <template>
               <span>{{ $store.state.user.realName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="发起时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="realityMoney" label="采购金额（元）" header-align="center" align="center"></el-table-column>
        <el-table-column  label="状态" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{status[scope.row.status]}}</span>
          </template>
        </el-table-column>
        <el-table-column  label="操作" header-align="center" align="center">
                    <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="todetails(scope.row)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      ></el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
/* eslint-disable */
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./batchorder-add-or-update";
import Cookies from "js-cookie";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      status:["待提交","已提交","已完成",],
      topData: {},
      mixinViewModuleOptions: {
        getDataListURL: "canteens/batchorder/getOrder",
        getDataListIsPage: true,
        exportURL: "/canteens/batchorder/export",
        deleteURL: "/canteens/batchorder",
        deleteIsBatch: true
      },
      dataForm: {
        batchOrderId: ""
      }
    };
  },
  activated: function() {
    this.getTableData();
  },
  methods: {
    addData() {
      this.$router.push({ name: "canteens-batchordermx" ,params: { add:true }},);
    },
    selectChange(param,param1,param2,){
      this.secectList=param
    },
    upDateOrder(){
      var data =[]
      this.secectList.map(item=>{
        data.push(item.batchOrderId)
      })
      data=data.join(',')
     this.$http
        .post("canteens/batchorder/update", {ids:data,})
        .then(({ data: res }) => {
     this.getTableData()
           
        })
        .catch(() => {});
    },
    todetails(val){
  const {batchOrderId,status }= val
 this.$router.push({ name: "canteens-batchordermx" ,params: {batchOrderId,status}},);
    },
    getTableData() {
      var data = this.topData;
      data.supplierId = this.$store.state.user.id;
      this.$http
        .get("canteens/batchorder/getOrder", data)
        .then(({ data: res }) => {
          console.log(res);
          this.dataList = res.data.list;
        })
        .catch(() => {});
    }
  },
  components: {
    AddOrUpdate
  }
};
</script>
